﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public IList<RetailOnlineSite.Transfer.CategoryDTO> LoadCategory()
    {
        RetailOnlineSite.Data.ICategoryDataAccess dataAccess = new RetailOnlineSite.Data.CategoryDataAccess();
        return dataAccess.GetChildren();
    }

    [WebMethod]
    public IList<RetailOnlineSite.Transfer.CategoryDTO> LoadTopCategories()
    {
        RetailOnlineSite.Data.ICategoryDataAccess dataAccess = new RetailOnlineSite.Data.CategoryDataAccess();
        return dataAccess.GetTop();
    }

    [WebMethod]
    public IList<RetailOnlineSite.Transfer.CategoryDTO> LoadNewCategories()
    {
        RetailOnlineSite.Data.ICategoryDataAccess dataAccess = new RetailOnlineSite.Data.CategoryDataAccess();
        return dataAccess.GetTop();
    }

    [WebMethod]
    public IList<RetailOnlineSite.Transfer.CategoryDTO> LoadSHCategories()
    {
        RetailOnlineSite.Data.ICategoryDataAccess dataAccess = new RetailOnlineSite.Data.CategoryDataAccess();
        return dataAccess.GetTop();
    }

    [WebMethod]
    public IList<RetailOnlineSite.Transfer.ProductDTO> LoadProducts(Guid categoryID)
    {
        RetailOnlineSite.Data.IProductDataAccess dataAccess = new RetailOnlineSite.Data.ProductDataAccess();
        //string control = RenderPartialToString("UI/ItemUI.ascx");
        return dataAccess.GetByCategory(categoryID);
    }

    //private string RenderPartialToString(string controlName)
    //{
    //    System.Web.UI.Page page = new System.Web.UI.Page();
    //    System.Web.UI.Control control = page.LoadControl(controlName);
    //    page.Controls.Add(control);

    //    System.IO.StringWriter writer = new System.IO.StringWriter();
    //    HttpContext.Current.Server.Execute(page, writer, false);

    //    return writer.ToString();
    //}

}
